<%@ page language="java" 
import="it.polimi.swim.entity.SystemUser, java.util.List, it.polimi.swim.entity.Skill"
contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="myStyle.css">
<title>Home</title>
</head>
<body>
<%String err = (String) request.getAttribute("errorMessage");
if(err!=null){
System.out.print(err);%>
<script type="text/javascript">
window.alert("wee");
</script>
<%}
if(request.getAttribute("skillList")==null){
		response.sendRedirect("AvailableSkillsServlet?path=/homeUser.jsp");
	}
%> 
<div id='header' >
	<div style="float:left"><a href="homeUser.jsp">SWIMv2</a></div>
	<div style="float:right;"><a href="SignoutServlet">Sign out</a></div>
</div>
<div id="content">
<br>
	<%//Esiste una sessione aperta
	if(session.getAttribute("mail")!=null){
		%>
<div style='float:left;'>
	<div style='float:left;'>
		<ul id='menuHome'>
			<li><a href='EditProfileServlet'>Edit Profile</a></li>
			<li><a href='AvailableSkillsServlet?path=/helpRequestForm.jsp'>Create help request</a></li>
			<li><a href='MyFriendsServlet'>My Friends</a></li>
			<li><a href='notifications.jsp'>Notifications</a></li>
			<li><a href='newSkillForm.jsp'>Request a new skill</a></li>
			<li><a href='MyHelpServlet'>My Help Requests</a></li>
		</ul>
	</div>
	<div style='float:right;' class="homeUserContent">
		<div style='float:left;margin-top:15px;padding-right: 30px;'>
		<%out.println("Name: <b>"+session.getAttribute("name")+"</b>"+
				"<br>Surname: <b>"+session.getAttribute("surname")+"</b>"+
				"<br>City: <b>"+session.getAttribute("city")+"</b><br>"); %>
		</div>
		<div style='float:right;' class=rightCell>
		Your Skills:<br>
		<%
		List<Skill> skills = (List<Skill>)session.getAttribute("skillList");
		for(Skill s:skills){
			out.print("<i>"+s.getName()+"</i><br>");
		}
		%>
		</div>
	</div>
</div>
	
<div style='float:right;' class="searchHome">
		<table>
		<tr><td>
		<form method="post" action="SearchServlet">
			<label>Search by Name</label><br>
			<input type="text" name="user" value="Name Surname" />
			<input type="hidden" name="action" value="searchUser">
			<input type="submit" value="Search">
		</form>
		<br style="line"><hr>
		</td></tr>
		<tr><td>
		<br>
		<form method="post" action="SearchServlet">
		<label>Search by Skill</label><br>
		<%
		if(request.getAttribute("skillList")!=null){
			List<Skill> skillList=(List<Skill>)request.getAttribute("skillList");
			
			out.println("<select name='skill'>");
			for(Skill s:skillList ){
				out.println("<option value="+s.getId()+">"+s.getName()+"</option>");
			}
			out.println("</select>");
		}
		%>
		<input type="submit" value="Search"> 
		<input type="hidden" name="action" value="usersBySkill">
		</form>
		</td></tr>
		</table>
</div>
</div>
	<%
	
	}
	else{
		out.println("<a href='index.jsp'>Log in</a>");
	}
	%>
</body>
</html>